<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/layui/css/layui.css"/>
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/mylay.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body">


            <table id="LAY-table" lay-filter="LAY-table"></table>
            <script type="text/html" id="pic">
           
                <img src="{{d.prc}}" title="点击放大" lay-event="show">
                <span style="display:none;" id="pic{{d.id}}"><img src="{{d.prc}}"></span>
            </script>
        
            <script type="text/html" id="table-webuser">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
            <script type="text/html" id="table-tmb">
           
            </script>
        </div>
    </div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/Application/iframe/assets/libs/layuiadmin/layui/layui.js"></script>
<script>
    var url = '/admin/ads';
    layui.config({
        base: '/Application/iframe/assets/libs/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'table', 'form'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        //初始化列表
        table.render({
            elem: '#LAY-table'
            ,url: "{:U('Merchant/ShoppingMall/shop_img_ajax')}"+"?id="+"{$id}" //接口
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', width: 200, title: 'id', sort: true,}
                ,{field: 'prc', width: 200, title: '图片', sort: true, toolbar: '#pic'}
                
                ,{title: '操作', width: 300, align:'center', fixed: 'right', toolbar: '#table-webuser'}
            ]]
            ,page: true
            ,limit: 20
            ,height: 'full-100'
            ,text: {none: '暂无相关数据'}
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res)

                return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本

                  "data": res.data //解析数据列表
                };
              }
        });

        //监听编辑+单个删除
        table.on('tool(LAY-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        type:"GET",
                        url:"{:U('Merchant/shoppingMall/del_img')}",
                        data: {id:data.id,goods_id:data.goods_id},
                        dataType:"json",
                        beforeSend: function () {
                            layer.load(1);
                        },
                        success:function(res){
                            layer.closeAll();
                            if(res.code == 1001){
                                obj.del();
                                table.reload('LAY-table', {
                                  url: "{:U('Merchant/ShoppingMall/shop_img_ajax')}"
                                  ,where: {id:"{$id}"} //设定异步数据接口的额外参数
                                  //,height: 300
                                });
                               // table.reload('LAY-table',{where: {time:new Date()}}); //数据刷新
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                });
                
            }
            
        });

        //批量删除+添加
        var active = {
            batchdel: function(){
                var checkStatus = table.checkStatus('LAY-table')
                    ,checkData = checkStatus.data //得到选中的数据
                    ,ids = "0";
                if(checkData.length === 0){
                    return layer.msg('请选择数据');
                }
                $.each(checkData,function(key,value){
                    ids = ids + "," + checkData[key]['id'];
                });
                layer.confirm('确定删除吗？', function(index) {
                    $.ajax({
                        type:"post",
                        url:"{:U('Merchant/shoppingMall/del_shop')}",
                        data: {id:ids},
                        dataType:"json",
                        beforeSend: function () {
                            layer.load(1);
                        },
                        success:function(res){
                            layer.closeAll();
                            if(res.code == 1001){
                                table.reload('LAY-table',{where: {time:new Date()}});
                                layer.msg('已删除');
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                });
            }
            
        };

        $('.layui-btn.btn-top').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
            var arr = new Array();
    $(".layui-form-checked").click(function(){
        alert('s');
         $("input:checkbox[name='spec_id[]']:checked").each(function(i){
            arr[i] = $(this).val();
        });
        var arrData = arr.join(",");
        $("#a").val(arrData)
        console.log();
    })
    });
</script>
</body>
</html>